﻿using EyFramework.Common;
using EyFramework.Sys.Core.Dao;
using EyFramework.Sys.Entity;
using System.Collections.Generic;

namespace EyFramework.Sys.Core.Service.Impl
{
    public class SysUserService : BaseHisService, ISysUserService
    {
        protected readonly ISysUserDao _sysUserDao;

        public SysUserService(ISysUserDao sysUserDao)
        {
            _sysUserDao = sysUserDao;
        }

        public SysUser CheckAccount(string pLoginName, string pPassword)
        {
            SysUser scUsr = GetUserByUserName(pLoginName);
            if (scUsr != null)
            {
                if (scUsr.PASSWORD != pPassword)
                {
                    throw new BizException("登录失败，请确认用户名和密码是否正确！");
                }
            }
            else
            {
                throw new BizException("登录失败，未找到指定用户,请确认用户名是否正确！");
            }
            return scUsr;
        }

        public List<SysUser> SelectAllUsers()
        {
            return _sysUserDao.GetList();
        }

        private SysUser GetUserByUserName(string pLoginName)
        {
            return _sysUserDao.GetUserByUserName(pLoginName);
        }
    }
}